<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.10"/>
<title>Introduction_to_Algorithms: src/graph_algorithms/basic_graph/graph_representation/graph/graph.h Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { init_search(); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">Introduction_to_Algorithms
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.10 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('graph_8h_source.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">graph.h</div>  </div>
</div><!--header-->
<div class="contents">
<a href="graph_8h.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;<span class="comment">/*</span></div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"> * Copyright 2016- huaxz &lt;huaxz1986@163.com&gt;</span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * This program is free software: you can redistribute it and/or modify</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> * it under the terms of the GNU General Public License as published by</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> * the Free Software Foundation, either version 2 of the License, or</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment"> * (at your option) any later version.</span></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="comment"> * This program is distributed in the hope that it will be useful,</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment"> * but WITHOUT ANY WARRANTY; without even the implied warranty of</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="comment"> * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="comment"> * GNU General Public License for more details.</span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="comment"> * You should have received a copy of the GNU General Public License</span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="comment"> * along with this program.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span></div>
<div class="line"><a name="l00016"></a><span class="lineno">   16</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="comment"> * Author: huaxz1986@163.com (huaxz)</span></div>
<div class="line"><a name="l00018"></a><span class="lineno">   18</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;<span class="preprocessor">#ifndef GRAPH</span></div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="preprocessor">#define GRAPH</span></div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="preprocessor">#include&quot;../matrix_graph/matrixgraph.h&quot;</span></div>
<div class="line"><a name="l00022"></a><span class="lineno">   22</span>&#160;<span class="preprocessor">#include&quot;../adjlist_graph/adjlistgraph.h&quot;</span></div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="preprocessor">#include&lt;array&gt;</span></div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="preprocessor">#include&lt;memory&gt;</span></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="preprocessor">#include&lt;assert.h&gt;</span></div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="keyword">namespace </span><a class="code" href="namespace_introduction_to_algorithm.html">IntroductionToAlgorithm</a></div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;{</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;    <span class="keyword">namespace </span>GraphAlgorithm</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;    {</div>
<div class="line"><a name="l00031"></a><span class="lineno">   31</span>&#160;</div>
<div class="line"><a name="l00042"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html">   42</a></span>&#160;        <span class="keyword">template</span>&lt;<span class="keywordtype">unsigned</span> N,<span class="keyword">typename</span> VType&gt; <span class="keyword">struct </span><a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html">Graph</a></div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;        {</div>
<div class="line"><a name="l00044"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a507632614d13e91d29acbf8acb0b0f0f">   44</a></span>&#160;            <span class="keyword">typedef</span> <span class="keywordtype">int</span> <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a507632614d13e91d29acbf8acb0b0f0f">VIDType</a>;     </div>
<div class="line"><a name="l00045"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a77f6d3ef31203e0d6ebd2ed87928978a">   45</a></span>&#160;            <span class="keyword">typedef</span> <span class="keywordtype">int</span> <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a77f6d3ef31203e0d6ebd2ed87928978a">EWeightType</a>; </div>
<div class="line"><a name="l00046"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#ad1eb485d135eb8076a44b00904ae2f5a">   46</a></span>&#160;            <span class="keyword">typedef</span> std::tuple&lt;VIDType,VIDType,EWeightType&gt; <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#ad1eb485d135eb8076a44b00904ae2f5a">EdgeTupleType</a>; </div>
<div class="line"><a name="l00047"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a95fc613ee7f50f11c84d56c19dc6d321">   47</a></span>&#160;            <span class="keyword">typedef</span> VType <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a95fc613ee7f50f11c84d56c19dc6d321">VertexType</a>; </div>
<div class="line"><a name="l00048"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aba53db2c8cade306553fc1e03f138aa2">   48</a></span>&#160;            <span class="keyword">static</span> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aba53db2c8cade306553fc1e03f138aa2">NUM</a>=N; </div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;</div>
<div class="line"><a name="l00054"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a1effb22f7cc51898e54bbb3a5f549c95">   54</a></span>&#160;            <span class="keyword">explicit</span> <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a1effb22f7cc51898e54bbb3a5f549c95">Graph</a>(EWeightType val):<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a498323460ec613f12e1039afdca6c10a">matrix</a>(val),<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a07a8f2eafc8175787a6ce1f26f1252d0">next_empty_vertex</a>(0)</div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;            {}</div>
<div class="line"><a name="l00057"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a554fe807fb375fe4e56e5b0a0ac21477">   57</a></span>&#160;            <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a554fe807fb375fe4e56e5b0a0ac21477">Graph</a>():<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a07a8f2eafc8175787a6ce1f26f1252d0">next_empty_vertex</a>(0){}</div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;</div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;</div>
<div class="line"><a name="l00068"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a172f460e7f689fa42dcb3f1130d3fa64">   68</a></span>&#160;            VIDType <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a172f460e7f689fa42dcb3f1130d3fa64">add_vertex</a>(<span class="keyword">const</span> <span class="keyword">typename</span> VertexType::KeyType&amp; key)</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;            {</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;                <span class="keywordflow">while</span>(<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a07a8f2eafc8175787a6ce1f26f1252d0">next_empty_vertex</a>&lt;N&amp;&amp;<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aea254564996a6a172f001ebf7f3c5f65">vertexes</a>.at(<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a07a8f2eafc8175787a6ce1f26f1252d0">next_empty_vertex</a>))</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;                    <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a07a8f2eafc8175787a6ce1f26f1252d0">next_empty_vertex</a>++;</div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;                <span class="keywordflow">if</span>(<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a07a8f2eafc8175787a6ce1f26f1252d0">next_empty_vertex</a>&gt;=N)</div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;                    <span class="keywordflow">throw</span> std::invalid_argument(<span class="stringliteral">&quot;add_vertex error:Graph Vertex is full, can not add vertex.&quot;</span>);</div>
<div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;                VIDType v_id=<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a07a8f2eafc8175787a6ce1f26f1252d0">next_empty_vertex</a>;</div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;                <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aea254564996a6a172f001ebf7f3c5f65">vertexes</a>.at(<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a07a8f2eafc8175787a6ce1f26f1252d0">next_empty_vertex</a>)=std::make_shared&lt;VertexType&gt;(key,v_id);</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;                <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a07a8f2eafc8175787a6ce1f26f1252d0">next_empty_vertex</a>++;</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;                <span class="keywordflow">return</span> v_id;</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;            }</div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;</div>
<div class="line"><a name="l00088"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#ad22898c16f9f614c0826bd62500317de">   88</a></span>&#160;            VIDType <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#ad22898c16f9f614c0826bd62500317de">add_vertex</a>(<span class="keyword">const</span> <span class="keyword">typename</span> VertexType::KeyType &amp;key,VIDType <span class="keywordtype">id</span>)</div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;            {</div>
<div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;                <span class="keywordflow">if</span>(id&lt;0||id&gt;=N)</div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;                    <span class="keywordflow">throw</span> std::invalid_argument(<span class="stringliteral">&quot;add_vertex error:id must &gt;=0 and &lt;N.&quot;</span>);</div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;                <span class="keywordflow">if</span>(<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aea254564996a6a172f001ebf7f3c5f65">vertexes</a>.at(<span class="keywordtype">id</span>))</div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;                    <span class="keywordflow">throw</span> std::invalid_argument(<span class="stringliteral">&quot;add_vertex error: vertex of id has existed.&quot;</span>);</div>
<div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;                <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aea254564996a6a172f001ebf7f3c5f65">vertexes</a>.at(<span class="keywordtype">id</span>)=std::make_shared&lt;VertexType&gt;(key,id);</div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;                <span class="keywordflow">return</span> id;</div>
<div class="line"><a name="l00096"></a><span class="lineno">   96</span>&#160;            }</div>
<div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;</div>
<div class="line"><a name="l00105"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#ae36e2ef188da844f75a673516a6c7225">  105</a></span>&#160;            <span class="keywordtype">void</span> <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#ae36e2ef188da844f75a673516a6c7225">modify_vertex</a>(<span class="keyword">const</span> <span class="keyword">typename</span> VertexType::KeyType &amp;newkey,VIDType <span class="keywordtype">id</span>)</div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;            {</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;                <span class="keywordflow">if</span>(id&lt;0||id&gt;=N)</div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;                    <span class="keywordflow">throw</span> std::invalid_argument(<span class="stringliteral">&quot;modify_vertex error:id must &gt;=0 and &lt;N.&quot;</span>);</div>
<div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;                <span class="keywordflow">if</span>(!<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aea254564996a6a172f001ebf7f3c5f65">vertexes</a>.at(<span class="keywordtype">id</span>))</div>
<div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;                    <span class="keywordflow">throw</span> std::invalid_argument(<span class="stringliteral">&quot;modify_vertex error: vertex of id does not exist.&quot;</span>);</div>
<div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;                <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aea254564996a6a172f001ebf7f3c5f65">vertexes</a>.at(<span class="keywordtype">id</span>)-&gt;key=newkey;</div>
<div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;            }</div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;</div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;</div>
<div class="line"><a name="l00129"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a3ddca71ba690d09471a7de78bcaa6fea">  129</a></span>&#160;            <span class="keywordtype">void</span> <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a3ddca71ba690d09471a7de78bcaa6fea">add_edge</a>(<span class="keyword">const</span> EdgeTupleType&amp; edge_tuple)</div>
<div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;            {</div>
<div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;                <span class="keyword">auto</span> id1=std::get&lt;0&gt;(edge_tuple);</div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;                <span class="keyword">auto</span> id2=std::get&lt;1&gt;(edge_tuple);</div>
<div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;</div>
<div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;                <span class="keywordflow">if</span>(id1&lt;0||id1&gt;=N||id2&lt;0||id2&gt;=N)</div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;                    <span class="keywordflow">throw</span> std::invalid_argument(<span class="stringliteral">&quot;add edge error:id must &gt;=0 and &lt;N.&quot;</span>);</div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;                <span class="keywordflow">if</span>(!<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aea254564996a6a172f001ebf7f3c5f65">vertexes</a>.at(id1) || !<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aea254564996a6a172f001ebf7f3c5f65">vertexes</a>.at(id2))</div>
<div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;                    <span class="keywordflow">throw</span> std::invalid_argument(<span class="stringliteral">&quot;add edge error: vertex of id does not exist.&quot;</span>);</div>
<div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;                <span class="keywordflow">if</span>(std::get&lt;2&gt;(edge_tuple)==<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a498323460ec613f12e1039afdca6c10a">matrix</a>.invalid_weight) <span class="keywordflow">return</span>;</div>
<div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;                <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a498323460ec613f12e1039afdca6c10a">matrix</a>.add_edge(edge_tuple);</div>
<div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;                <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a4442db9dd1bbb7fe543353df4fa1ba9f">adjList</a>.add_edge(edge_tuple);</div>
<div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;            }</div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;</div>
<div class="line"><a name="l00151"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#abda82467495ef0109b14061a6bbe84b9">  151</a></span>&#160;            <span class="keyword">template</span>&lt;<span class="keyword">typename</span> Iterator&gt; <span class="keywordtype">void</span> <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#abda82467495ef0109b14061a6bbe84b9">add_edges</a>(<span class="keyword">const</span> Iterator&amp;begin ,<span class="keyword">const</span> Iterator&amp;end)</div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;            {</div>
<div class="line"><a name="l00153"></a><span class="lineno">  153</span>&#160;</div>
<div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;                <span class="keywordflow">if</span>(std::distance(begin,end)&lt;=0)</div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;                    <span class="keywordflow">return</span>;</div>
<div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;                Iterator iter=begin;</div>
<div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;                <span class="keywordflow">while</span>(iter!=end)</div>
<div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;                {</div>
<div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;                    <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a3ddca71ba690d09471a7de78bcaa6fea">add_edge</a>(*iter);</div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;                    iter++;</div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;                }</div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;            }</div>
<div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;</div>
<div class="line"><a name="l00174"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#abfbc7f8a38017fd1422b5c6f1e8b6594">  174</a></span>&#160;            <span class="keywordtype">void</span> <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#abfbc7f8a38017fd1422b5c6f1e8b6594">adjust_edge</a>(VIDType id1,VIDType id2,EWeightType wt)</div>
<div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;            {</div>
<div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;                <span class="keywordflow">if</span>(id1&lt;0||id1&gt;=N||id2&lt;0||id2&gt;=N)</div>
<div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;                    <span class="keywordflow">throw</span> std::invalid_argument(<span class="stringliteral">&quot;adjust edge error:id must &gt;=0 and &lt;N.&quot;</span>);</div>
<div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;                <span class="keywordflow">if</span>(!<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aea254564996a6a172f001ebf7f3c5f65">vertexes</a>.at(id1) || !<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aea254564996a6a172f001ebf7f3c5f65">vertexes</a>.at(id2))</div>
<div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160;                    <span class="keywordflow">throw</span> std::invalid_argument(<span class="stringliteral">&quot;adjust edge error: vertex of id does not exist.&quot;</span>);</div>
<div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160;                <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a498323460ec613f12e1039afdca6c10a">matrix</a>.adjust_edge(id1,id2,wt);</div>
<div class="line"><a name="l00181"></a><span class="lineno">  181</span>&#160;                <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a4442db9dd1bbb7fe543353df4fa1ba9f">adjList</a>.adjust_edge(id1,id2,wt);</div>
<div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;            }</div>
<div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;</div>
<div class="line"><a name="l00189"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a0cadf10557297a2cb10aec457eb70b3f">  189</a></span>&#160;            <span class="keyword">const</span> std::vector&lt;EdgeTupleType&gt; <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a0cadf10557297a2cb10aec457eb70b3f">edge_tuples</a>()<span class="keyword"> const</span></div>
<div class="line"><a name="l00190"></a><span class="lineno">  190</span>&#160;<span class="keyword">            </span>{</div>
<div class="line"><a name="l00191"></a><span class="lineno">  191</span>&#160;                <span class="keyword">auto</span> edges1=<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a498323460ec613f12e1039afdca6c10a">matrix</a>.edge_tuples();</div>
<div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160;                <span class="keyword">auto</span> edges2=<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a4442db9dd1bbb7fe543353df4fa1ba9f">adjList</a>.edge_tuples();</div>
<div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;                <span class="keyword">auto</span> compare=[](<span class="keyword">const</span> EdgeTupleType&amp; e1,<span class="keyword">const</span> EdgeTupleType&amp;e2)-&gt;<span class="keywordtype">bool</span> {</div>
<div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;                    <span class="keywordflow">if</span>(</div>
<div class="line"><a name="l00195"></a><span class="lineno">  195</span>&#160;                            (std::get&lt;0&gt;(e1) &lt; std::get&lt;0&gt;(e2))||</div>
<div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;                            ( (std::get&lt;0&gt;(e1) == std::get&lt;0&gt;(e2))&amp;&amp;(std::get&lt;1&gt;(e1) &lt; std::get&lt;1&gt;(e2)) ) ||</div>
<div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;                            ( (std::get&lt;0&gt;(e1) == std::get&lt;0&gt;(e2))&amp;&amp;(std::get&lt;1&gt;(e1) == std::get&lt;1&gt;(e2))&amp;&amp;(std::get&lt;2&gt;(e1) &lt; std::get&lt;2&gt;(e2)) )</div>
<div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;                        ) <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;                   <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;                };</div>
<div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;                std::sort(edges1.begin(),edges1.end(),compare);</div>
<div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;                std::sort(edges2.begin(),edges2.end(),compare);</div>
<div class="line"><a name="l00203"></a><span class="lineno">  203</span>&#160;                assert(edges1==edges2);</div>
<div class="line"><a name="l00204"></a><span class="lineno">  204</span>&#160;                <span class="keywordflow">return</span> edges1;</div>
<div class="line"><a name="l00205"></a><span class="lineno">  205</span>&#160;            }</div>
<div class="line"><a name="l00206"></a><span class="lineno">  206</span>&#160;</div>
<div class="line"><a name="l00208"></a><span class="lineno">  208</span>&#160;</div>
<div class="line"><a name="l00217"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a1a36b41adf54b242ff40610eae219eda">  217</a></span>&#160;            <span class="keyword">const</span> std::vector&lt;EdgeTupleType&gt; <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a1a36b41adf54b242ff40610eae219eda">vertex_edge_tuples</a>(VIDType <span class="keywordtype">id</span>)<span class="keyword"> const</span></div>
<div class="line"><a name="l00218"></a><span class="lineno">  218</span>&#160;<span class="keyword">            </span>{</div>
<div class="line"><a name="l00219"></a><span class="lineno">  219</span>&#160;                <span class="keywordflow">if</span>(id&lt;0||id&gt;=N)</div>
<div class="line"><a name="l00220"></a><span class="lineno">  220</span>&#160;                    <span class="keywordflow">throw</span> std::invalid_argument(<span class="stringliteral">&quot;vertex_edge_tuples error:id must &gt;=0 and &lt;N.&quot;</span>);</div>
<div class="line"><a name="l00221"></a><span class="lineno">  221</span>&#160;                <span class="keywordflow">if</span>(!<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aea254564996a6a172f001ebf7f3c5f65">vertexes</a>.at(<span class="keywordtype">id</span>))</div>
<div class="line"><a name="l00222"></a><span class="lineno">  222</span>&#160;                    <span class="keywordflow">throw</span> std::invalid_argument(<span class="stringliteral">&quot;vertex_edge_tuples error: vertex of id does not exist.&quot;</span>);</div>
<div class="line"><a name="l00223"></a><span class="lineno">  223</span>&#160;</div>
<div class="line"><a name="l00224"></a><span class="lineno">  224</span>&#160;                <span class="keyword">auto</span> edges1=<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a498323460ec613f12e1039afdca6c10a">matrix</a>.vertex_edge_tuples(<span class="keywordtype">id</span>);</div>
<div class="line"><a name="l00225"></a><span class="lineno">  225</span>&#160;                <span class="keyword">auto</span> edges2=<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a4442db9dd1bbb7fe543353df4fa1ba9f">adjList</a>.vertex_edge_tuples(<span class="keywordtype">id</span>);</div>
<div class="line"><a name="l00226"></a><span class="lineno">  226</span>&#160;                <span class="keyword">auto</span> compare=[](<span class="keyword">const</span> EdgeTupleType&amp; e1,<span class="keyword">const</span> EdgeTupleType&amp;e2)-&gt;<span class="keywordtype">bool</span> {</div>
<div class="line"><a name="l00227"></a><span class="lineno">  227</span>&#160;                    <span class="keywordflow">if</span>(</div>
<div class="line"><a name="l00228"></a><span class="lineno">  228</span>&#160;                            (std::get&lt;0&gt;(e1) &lt; std::get&lt;0&gt;(e2))||</div>
<div class="line"><a name="l00229"></a><span class="lineno">  229</span>&#160;                            ( (std::get&lt;0&gt;(e1) == std::get&lt;0&gt;(e2))&amp;&amp;(std::get&lt;1&gt;(e1) &lt; std::get&lt;1&gt;(e2)) ) ||</div>
<div class="line"><a name="l00230"></a><span class="lineno">  230</span>&#160;                            ( (std::get&lt;0&gt;(e1) == std::get&lt;0&gt;(e2))&amp;&amp;(std::get&lt;1&gt;(e1) == std::get&lt;1&gt;(e2))&amp;&amp;(std::get&lt;2&gt;(e1) &lt; std::get&lt;2&gt;(e2)) )</div>
<div class="line"><a name="l00231"></a><span class="lineno">  231</span>&#160;                        ) <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a name="l00232"></a><span class="lineno">  232</span>&#160;                   <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00233"></a><span class="lineno">  233</span>&#160;                };</div>
<div class="line"><a name="l00234"></a><span class="lineno">  234</span>&#160;                std::sort(edges1.begin(),edges1.end(),compare);</div>
<div class="line"><a name="l00235"></a><span class="lineno">  235</span>&#160;                std::sort(edges2.begin(),edges2.end(),compare);</div>
<div class="line"><a name="l00236"></a><span class="lineno">  236</span>&#160;                assert(edges1==edges2);</div>
<div class="line"><a name="l00237"></a><span class="lineno">  237</span>&#160;                <span class="keywordflow">return</span> edges1;</div>
<div class="line"><a name="l00238"></a><span class="lineno">  238</span>&#160;            }</div>
<div class="line"><a name="l00239"></a><span class="lineno">  239</span>&#160;</div>
<div class="line"><a name="l00241"></a><span class="lineno">  241</span>&#160;</div>
<div class="line"><a name="l00253"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#ac6f3559ac73a84a45285d2906b9f7557">  253</a></span>&#160;            <span class="keywordtype">bool</span> <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#ac6f3559ac73a84a45285d2906b9f7557">has_edge</a>(VIDType id_from,VIDType id_to)<span class="keyword"> const</span></div>
<div class="line"><a name="l00254"></a><span class="lineno">  254</span>&#160;<span class="keyword">            </span>{</div>
<div class="line"><a name="l00255"></a><span class="lineno">  255</span>&#160;                <span class="keywordflow">if</span>(id_from&lt;0||id_from&gt;=N||id_to&lt;0||id_to&gt;=N)</div>
<div class="line"><a name="l00256"></a><span class="lineno">  256</span>&#160;                    <span class="keywordflow">throw</span> std::invalid_argument(<span class="stringliteral">&quot;has edge error:id must &gt;=0 and &lt;N.&quot;</span>);</div>
<div class="line"><a name="l00257"></a><span class="lineno">  257</span>&#160;                <span class="keywordflow">if</span>(!<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aea254564996a6a172f001ebf7f3c5f65">vertexes</a>.at(id_from) || !<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aea254564996a6a172f001ebf7f3c5f65">vertexes</a>.at(id_to))</div>
<div class="line"><a name="l00258"></a><span class="lineno">  258</span>&#160;                    <span class="keywordflow">throw</span> std::invalid_argument(<span class="stringliteral">&quot;has edge error: vertex of id does not exist.&quot;</span>);</div>
<div class="line"><a name="l00259"></a><span class="lineno">  259</span>&#160;               <span class="keyword">auto</span> m=<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a498323460ec613f12e1039afdca6c10a">matrix</a>.has_edge(id_from,id_to);</div>
<div class="line"><a name="l00260"></a><span class="lineno">  260</span>&#160;               <span class="keyword">auto</span> a=<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a4442db9dd1bbb7fe543353df4fa1ba9f">adjList</a>.has_edge(id_from,id_to);</div>
<div class="line"><a name="l00261"></a><span class="lineno">  261</span>&#160;               assert(<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a498323460ec613f12e1039afdca6c10a">matrix</a>.has_edge(id_from,id_to)==<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a4442db9dd1bbb7fe543353df4fa1ba9f">adjList</a>.has_edge(id_from,id_to));</div>
<div class="line"><a name="l00262"></a><span class="lineno">  262</span>&#160;               <span class="keywordflow">return</span> <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a498323460ec613f12e1039afdca6c10a">matrix</a>.has_edge(id_from,id_to);</div>
<div class="line"><a name="l00263"></a><span class="lineno">  263</span>&#160;            }</div>
<div class="line"><a name="l00264"></a><span class="lineno">  264</span>&#160;</div>
<div class="line"><a name="l00266"></a><span class="lineno">  266</span>&#160;</div>
<div class="line"><a name="l00278"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a9736f238bdedf0d6fccc064e6acea65d">  278</a></span>&#160;            EWeightType <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a9736f238bdedf0d6fccc064e6acea65d">weight</a>(VIDType id_from,VIDType id_to)<span class="keyword"> const</span></div>
<div class="line"><a name="l00279"></a><span class="lineno">  279</span>&#160;<span class="keyword">            </span>{</div>
<div class="line"><a name="l00280"></a><span class="lineno">  280</span>&#160;                <span class="keywordflow">if</span>(id_from&lt;0||id_from&gt;=N||id_to&lt;0||id_to&gt;=N)</div>
<div class="line"><a name="l00281"></a><span class="lineno">  281</span>&#160;                    <span class="keywordflow">throw</span> std::invalid_argument(<span class="stringliteral">&quot;edge weight error:id must &gt;=0 and &lt;N.&quot;</span>);</div>
<div class="line"><a name="l00282"></a><span class="lineno">  282</span>&#160;                <span class="keywordflow">if</span>(!<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aea254564996a6a172f001ebf7f3c5f65">vertexes</a>.at(id_from) || !<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aea254564996a6a172f001ebf7f3c5f65">vertexes</a>.at(id_to))</div>
<div class="line"><a name="l00283"></a><span class="lineno">  283</span>&#160;                    <span class="keywordflow">throw</span> std::invalid_argument(<span class="stringliteral">&quot;edge weight error: vertex of id does not exist.&quot;</span>);</div>
<div class="line"><a name="l00284"></a><span class="lineno">  284</span>&#160;                assert(<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a498323460ec613f12e1039afdca6c10a">matrix</a>.weight(id_from,id_to)==<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a4442db9dd1bbb7fe543353df4fa1ba9f">adjList</a>.weight(id_from,id_to));</div>
<div class="line"><a name="l00285"></a><span class="lineno">  285</span>&#160;                <span class="keywordflow">return</span> <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a498323460ec613f12e1039afdca6c10a">matrix</a>.weight(id_from,id_to);</div>
<div class="line"><a name="l00286"></a><span class="lineno">  286</span>&#160;            }</div>
<div class="line"><a name="l00287"></a><span class="lineno">  287</span>&#160;</div>
<div class="line"><a name="l00289"></a><span class="lineno">  289</span>&#160;</div>
<div class="line"><a name="l00299"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aec06e55b6164700f65dcc08dafe79666">  299</a></span>&#160;            std::shared_ptr&lt;Graph&gt; <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aec06e55b6164700f65dcc08dafe79666">inverse</a>()</div>
<div class="line"><a name="l00300"></a><span class="lineno">  300</span>&#160;            {</div>
<div class="line"><a name="l00301"></a><span class="lineno">  301</span>&#160;                std::shared_ptr&lt;Graph&gt; graph=std::make_shared&lt;Graph&gt;(<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a498323460ec613f12e1039afdca6c10a">matrix</a>.invalid_weight);</div>
<div class="line"><a name="l00302"></a><span class="lineno">  302</span>&#160;                <span class="keywordflow">for</span>(<span class="keywordtype">int</span> i=0;i&lt;<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aea254564996a6a172f001ebf7f3c5f65">vertexes</a>.size();i++)</div>
<div class="line"><a name="l00303"></a><span class="lineno">  303</span>&#160;                {</div>
<div class="line"><a name="l00304"></a><span class="lineno">  304</span>&#160;                    <span class="keywordflow">if</span>(<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aea254564996a6a172f001ebf7f3c5f65">vertexes</a>.at(i))</div>
<div class="line"><a name="l00305"></a><span class="lineno">  305</span>&#160;                    {</div>
<div class="line"><a name="l00306"></a><span class="lineno">  306</span>&#160;                        graph-&gt;vertexes.at(i)=std::make_shared&lt;VertexType&gt;(<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aea254564996a6a172f001ebf7f3c5f65">vertexes</a>.at(i)-&gt;key,<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aea254564996a6a172f001ebf7f3c5f65">vertexes</a>.at(i)-&gt;id);</div>
<div class="line"><a name="l00307"></a><span class="lineno">  307</span>&#160;                    }</div>
<div class="line"><a name="l00308"></a><span class="lineno">  308</span>&#160;                }</div>
<div class="line"><a name="l00309"></a><span class="lineno">  309</span>&#160;                <span class="keyword">auto</span> edges=<a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a0cadf10557297a2cb10aec457eb70b3f">edge_tuples</a>();</div>
<div class="line"><a name="l00310"></a><span class="lineno">  310</span>&#160;                <span class="keywordflow">for</span>(<span class="keyword">auto</span>&amp;edge :edges)</div>
<div class="line"><a name="l00311"></a><span class="lineno">  311</span>&#160;                    std::swap(std::get&lt;0&gt;(edge),std::get&lt;1&gt;(edge));</div>
<div class="line"><a name="l00312"></a><span class="lineno">  312</span>&#160;                graph-&gt;add_edges(edges.begin(),edges.end());</div>
<div class="line"><a name="l00313"></a><span class="lineno">  313</span>&#160;                <span class="keywordflow">return</span> graph;</div>
<div class="line"><a name="l00314"></a><span class="lineno">  314</span>&#160;            }</div>
<div class="line"><a name="l00315"></a><span class="lineno">  315</span>&#160;</div>
<div class="line"><a name="l00316"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aea254564996a6a172f001ebf7f3c5f65">  316</a></span>&#160;            std::array&lt;std::shared_ptr&lt;VertexType&gt;,N&gt; <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aea254564996a6a172f001ebf7f3c5f65">vertexes</a>;</div>
<div class="line"><a name="l00317"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a07a8f2eafc8175787a6ce1f26f1252d0">  317</a></span>&#160;            std::size_t <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a07a8f2eafc8175787a6ce1f26f1252d0">next_empty_vertex</a>;</div>
<div class="line"><a name="l00318"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a498323460ec613f12e1039afdca6c10a">  318</a></span>&#160;            <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_matrix_graph.html">MatrixGraph&lt;N&gt;</a> <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a498323460ec613f12e1039afdca6c10a">matrix</a>;</div>
<div class="line"><a name="l00319"></a><span class="lineno"><a class="line" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a4442db9dd1bbb7fe543353df4fa1ba9f">  319</a></span>&#160;            <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_a_d_j_list_graph.html">ADJListGraph&lt;N&gt;</a> <a class="code" href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a4442db9dd1bbb7fe543353df4fa1ba9f">adjList</a>;</div>
<div class="line"><a name="l00320"></a><span class="lineno">  320</span>&#160;        };</div>
<div class="line"><a name="l00321"></a><span class="lineno">  321</span>&#160;    }</div>
<div class="line"><a name="l00322"></a><span class="lineno">  322</span>&#160;}</div>
<div class="line"><a name="l00323"></a><span class="lineno">  323</span>&#160;</div>
<div class="line"><a name="l00324"></a><span class="lineno">  324</span>&#160;</div>
<div class="line"><a name="l00325"></a><span class="lineno">  325</span>&#160;<span class="preprocessor">#endif // GRAPH</span></div>
<div class="line"><a name="l00326"></a><span class="lineno">  326</span>&#160;</div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html_a172f460e7f689fa42dcb3f1130d3fa64"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a172f460e7f689fa42dcb3f1130d3fa64">IntroductionToAlgorithm::GraphAlgorithm::Graph::add_vertex</a></div><div class="ttdeci">VIDType add_vertex(const typename VertexType::KeyType &amp;key)</div><div class="ttdoc">add_vertex:添加一个顶点 </div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00068">graph.h:68</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html_a95fc613ee7f50f11c84d56c19dc6d321"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a95fc613ee7f50f11c84d56c19dc6d321">IntroductionToAlgorithm::GraphAlgorithm::Graph::VertexType</a></div><div class="ttdeci">VType VertexType</div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00047">graph.h:47</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html_a77f6d3ef31203e0d6ebd2ed87928978a"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a77f6d3ef31203e0d6ebd2ed87928978a">IntroductionToAlgorithm::GraphAlgorithm::Graph::EWeightType</a></div><div class="ttdeci">int EWeightType</div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00045">graph.h:45</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html_ac6f3559ac73a84a45285d2906b9f7557"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#ac6f3559ac73a84a45285d2906b9f7557">IntroductionToAlgorithm::GraphAlgorithm::Graph::has_edge</a></div><div class="ttdeci">bool has_edge(VIDType id_from, VIDType id_to) const </div><div class="ttdoc">has_edge:返回图中指定顶点之间是否存在边 </div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00253">graph.h:253</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html_a554fe807fb375fe4e56e5b0a0ac21477"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a554fe807fb375fe4e56e5b0a0ac21477">IntroductionToAlgorithm::GraphAlgorithm::Graph::Graph</a></div><div class="ttdeci">Graph()</div><div class="ttdoc">默认构造函数 </div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00057">graph.h:57</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html_a9736f238bdedf0d6fccc064e6acea65d"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a9736f238bdedf0d6fccc064e6acea65d">IntroductionToAlgorithm::GraphAlgorithm::Graph::weight</a></div><div class="ttdeci">EWeightType weight(VIDType id_from, VIDType id_to) const </div><div class="ttdoc">weight:返回图中指定顶点之间的边的权重 </div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00278">graph.h:278</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html_abfbc7f8a38017fd1422b5c6f1e8b6594"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#abfbc7f8a38017fd1422b5c6f1e8b6594">IntroductionToAlgorithm::GraphAlgorithm::Graph::adjust_edge</a></div><div class="ttdeci">void adjust_edge(VIDType id1, VIDType id2, EWeightType wt)</div><div class="ttdoc">adjust_edge:修改一条边的权重 </div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00174">graph.h:174</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html_a1effb22f7cc51898e54bbb3a5f549c95"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a1effb22f7cc51898e54bbb3a5f549c95">IntroductionToAlgorithm::GraphAlgorithm::Graph::Graph</a></div><div class="ttdeci">Graph(EWeightType val)</div><div class="ttdoc">显式构造函数，为图的矩阵指定invalid_weight </div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00054">graph.h:54</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html_aea254564996a6a172f001ebf7f3c5f65"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aea254564996a6a172f001ebf7f3c5f65">IntroductionToAlgorithm::GraphAlgorithm::Graph::vertexes</a></div><div class="ttdeci">std::array&lt; std::shared_ptr&lt; VertexType &gt;, N &gt; vertexes</div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00316">graph.h:316</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html_a0cadf10557297a2cb10aec457eb70b3f"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a0cadf10557297a2cb10aec457eb70b3f">IntroductionToAlgorithm::GraphAlgorithm::Graph::edge_tuples</a></div><div class="ttdeci">const std::vector&lt; EdgeTupleType &gt; edge_tuples() const </div><div class="ttdoc">edge_tuples:返回图中所有边的三元素元组集合，这里集合采用std::vector<std::tuple<VIDType,VIDType,EWeightType>> </div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00189">graph.h:189</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html_aec06e55b6164700f65dcc08dafe79666"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aec06e55b6164700f65dcc08dafe79666">IntroductionToAlgorithm::GraphAlgorithm::Graph::inverse</a></div><div class="ttdeci">std::shared_ptr&lt; Graph &gt; inverse()</div><div class="ttdoc">inverse:返回图的一个镜像 </div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00299">graph.h:299</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html_a4442db9dd1bbb7fe543353df4fa1ba9f"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a4442db9dd1bbb7fe543353df4fa1ba9f">IntroductionToAlgorithm::GraphAlgorithm::Graph::adjList</a></div><div class="ttdeci">ADJListGraph&lt; N &gt; adjList</div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00319">graph.h:319</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html">IntroductionToAlgorithm::GraphAlgorithm::Graph</a></div><div class="ttdoc">Graph：图，算法导论22章22.1节 </div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00042">graph.h:42</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html_ad1eb485d135eb8076a44b00904ae2f5a"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#ad1eb485d135eb8076a44b00904ae2f5a">IntroductionToAlgorithm::GraphAlgorithm::Graph::EdgeTupleType</a></div><div class="ttdeci">std::tuple&lt; VIDType, VIDType, EWeightType &gt; EdgeTupleType</div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00046">graph.h:46</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html_a498323460ec613f12e1039afdca6c10a"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a498323460ec613f12e1039afdca6c10a">IntroductionToAlgorithm::GraphAlgorithm::Graph::matrix</a></div><div class="ttdeci">MatrixGraph&lt; N &gt; matrix</div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00318">graph.h:318</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html_aba53db2c8cade306553fc1e03f138aa2"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#aba53db2c8cade306553fc1e03f138aa2">IntroductionToAlgorithm::GraphAlgorithm::Graph::NUM</a></div><div class="ttdeci">static const unsigned NUM</div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00048">graph.h:48</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html_ad22898c16f9f614c0826bd62500317de"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#ad22898c16f9f614c0826bd62500317de">IntroductionToAlgorithm::GraphAlgorithm::Graph::add_vertex</a></div><div class="ttdeci">VIDType add_vertex(const typename VertexType::KeyType &amp;key, VIDType id)</div><div class="ttdoc">add_vertex:添加一个顶点 </div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00088">graph.h:88</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html_a507632614d13e91d29acbf8acb0b0f0f"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a507632614d13e91d29acbf8acb0b0f0f">IntroductionToAlgorithm::GraphAlgorithm::Graph::VIDType</a></div><div class="ttdeci">int VIDType</div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00044">graph.h:44</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html_a1a36b41adf54b242ff40610eae219eda"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a1a36b41adf54b242ff40610eae219eda">IntroductionToAlgorithm::GraphAlgorithm::Graph::vertex_edge_tuples</a></div><div class="ttdeci">const std::vector&lt; EdgeTupleType &gt; vertex_edge_tuples(VIDType id) const </div><div class="ttdoc">vertex_edge_tuples:返回图中从指定顶点出发的边的三元素元组集合，这里集合采用std::vector<std::tuple<VID...</div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00217">graph.h:217</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html_ae36e2ef188da844f75a673516a6c7225"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#ae36e2ef188da844f75a673516a6c7225">IntroductionToAlgorithm::GraphAlgorithm::Graph::modify_vertex</a></div><div class="ttdeci">void modify_vertex(const typename VertexType::KeyType &amp;newkey, VIDType id)</div><div class="ttdoc">modify_vertex:修改一个顶点的数据 </div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00105">graph.h:105</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html_a07a8f2eafc8175787a6ce1f26f1252d0"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a07a8f2eafc8175787a6ce1f26f1252d0">IntroductionToAlgorithm::GraphAlgorithm::Graph::next_empty_vertex</a></div><div class="ttdeci">std::size_t next_empty_vertex</div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00317">graph.h:317</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html_abda82467495ef0109b14061a6bbe84b9"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#abda82467495ef0109b14061a6bbe84b9">IntroductionToAlgorithm::GraphAlgorithm::Graph::add_edges</a></div><div class="ttdeci">void add_edges(const Iterator &amp;begin, const Iterator &amp;end)</div><div class="ttdoc">add_edges:添加一组边 </div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00151">graph.h:151</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_a_d_j_list_graph_html"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_a_d_j_list_graph.html">IntroductionToAlgorithm::GraphAlgorithm::ADJListGraph</a></div><div class="ttdoc">ADJListGraph：图的邻接表表示，算法导论22章22.1节 </div><div class="ttdef"><b>Definition:</b> <a href="adjlistgraph_8h_source.html#l00035">adjlistgraph.h:35</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_matrix_graph_html"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_matrix_graph.html">IntroductionToAlgorithm::GraphAlgorithm::MatrixGraph</a></div><div class="ttdoc">MatrixGraph：图的矩阵表示，算法导论22章22.1节 </div><div class="ttdef"><b>Definition:</b> <a href="matrixgraph_8h_source.html#l00037">matrixgraph.h:37</a></div></div>
<div class="ttc" id="namespace_introduction_to_algorithm_html"><div class="ttname"><a href="namespace_introduction_to_algorithm.html">IntroductionToAlgorithm</a></div><div class="ttdoc">Namespace of IntrodunctionToAlgorithm. </div><div class="ttdef"><b>Definition:</b> <a href="longest__common__subsequence_8h_source.html#l00024">longest_common_subsequence.h:24</a></div></div>
<div class="ttc" id="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph_html_a3ddca71ba690d09471a7de78bcaa6fea"><div class="ttname"><a href="struct_introduction_to_algorithm_1_1_graph_algorithm_1_1_graph.html#a3ddca71ba690d09471a7de78bcaa6fea">IntroductionToAlgorithm::GraphAlgorithm::Graph::add_edge</a></div><div class="ttdeci">void add_edge(const EdgeTupleType &amp;edge_tuple)</div><div class="ttdoc">add_edge:添加一条边 </div><div class="ttdef"><b>Definition:</b> <a href="graph_8h_source.html#l00129">graph.h:129</a></div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_8ed9dba4cd616b67da9b1338594e34e0.html">src</a></li><li class="navelem"><a class="el" href="dir_aa0a5ddea82682e3e6fbdbaa3337ee0e.html">graph_algorithms</a></li><li class="navelem"><a class="el" href="dir_7ed7dee3af3b488a5e053ec9bcb71f0e.html">basic_graph</a></li><li class="navelem"><a class="el" href="dir_d12496f1fc7378ee9aea361c57814de0.html">graph_representation</a></li><li class="navelem"><a class="el" href="dir_be16e826c8f11164c1ccdb50a2c38363.html">graph</a></li><li class="navelem"><a class="el" href="graph_8h.html">graph.h</a></li>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.10 </li>
  </ul>
</div>
</body>
</html>
